var http=require('http');
var argvArr=process.argv;
var fs=require('fs');
var path=require('path');

var fileName=argvArr[2];


http.createServer((req,res)=>{
    if(fileName){
        var filePath=path.join(__dirname,'/'+fileName);
        //fs.access也是判断文件是否存在的方法
        fs.exists(filePath,(err)=>{
            if(err==false){
                console.log('文件不存在')
            }
            else{
                var readable=fs.createReadStream(filePath);
                readable.pipe(res);
            }
        })
        
    }else{
        var filePath=path.join(__dirname,'/fileReader1.js');
        var readable=fs.createReadStream(filePath);
        readable.pipe(res);
    }
    
}).listen(8081);
console.log('sever is listening 8081');
